var Page;
var pageOption = {
    el: ".mainpage",
    data: {
        controller: "",
        grid: form.grid,
        gridselect: [],
        form: {},
        //用来保存每次多选框的值
        message: null,
        // 表格表头属性设置
        columns: [],
        //表格数据源
        tableData: [],
        // 分页数据
        currentPage: 1, //当前页
        pageSize: 10, //每页显示条目个数
        pageSizes: [10, 20, 50, 100], //每页显示个数选择器的选项设置
        total: 0, //	总条目数
    },
    methods: {
        add: function () {
            //添加
            form.list.add(this);
        },
        del: function () {
            form.list.del(this);
        },
        delSingle: function (id) {
            form.list.delSingle(this, id);
        },
        checkbox: function (checkval) {
            //多选框的值
            this.gridselect = checkval
        },
        isEmptyObject: function (obj) {
            //表格表头使用原生方法渲染
            for (var key in obj) {
                return false //返回false，不为空对象
            }
            return true //返回true，为空对象
        },
        goview: function (id) {
            //查看
            form.list.view(this, id);
        },
        goedit: function (id) {
            //编辑
            form.list.edit(this, id);
        },
        search: function () {
            //查询
            form.list.search(this, this.controller + "/search");
        },
        sizeChange: function (val) {
            //分页尺寸变化
            this.grid.pageSize = val;
            form.list.search(this, this.controller + "/search");
        },

        currentChange: function (val) {
            //当前页数变化
            this.grid.curPage = val;
            form.list.search(this, this.controller + "/search");
        },
        selectchange: function (selectchange) {
            //grid选中行变化
            this.gridselect = selectchange;
        },

        exportExcel: function (filename) {
            // 设置当前日期
            var time = new Date();
            var year = time.getFullYear();
            var month = time.getMonth() + 1;
            var day = time.getDate();
            var name = filename ? filename : (year + "" + month + "" + day);

            /* generate workbook object from table */
            //  .table要导出的是哪一个表格
            var wb = XLSX.utils.table_to_book(document.querySelector(".el-table"));
            /* get binary string as output */
            var wbout = XLSX.write(wb, {
                bookType: "xlsx",
                bookSST: true,
                type: "array"
            });
            try {
                //  name+'.xlsx'表示导出的excel表格名字
                saveAs(
                    new Blob([wbout], {
                        type: "application/octet-stream"
                    }),
                    name + ".xlsx"
                );
            } catch (e) {
                if (typeof console !== "undefined") console.log(e, wbout);
            }
            return wbout;
        },

    },
    mounted: function () {
        this.$nextTick(function () {
            //页面渲染完执行的操作
            form.list.init(this);
            //第一次查询数据
            form.list.search(Page, Page.controller + "/search");
        })
    }
};

window.onload = function () {
    //初始化Vue对象配置
    initVueOption(pageOption);
    //加载Vue对象
    Page = new Vue(pageOption);
}